<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Algorithm jSO</title>
<link rel="stylesheet" href="../math.css" type="text/css">
<meta name="generator" content="DocBook XSL Stylesheets V1.79.1">
<link rel="home" href="../index.html" title="Math Toolkit 4.2.1">
<link rel="up" href="../optimization.html" title="Chapter 11. Optimization">
<link rel="prev" href="differential_evolution.html" title="Differential Evolution">
<link rel="next" href="random_search.html" title="Random Search">
<meta name="viewport" content="width=device-width, initial-scale=1">
</head>
<body bgcolor="white" text="black" link="#0000FF" vlink="#840084" alink="#0000FF">
<table cellpadding="2" width="100%"><tr>
<td valign="top"><img alt="Boost C++ Libraries" width="277" height="86" src="../../../../../boost.png"></td>
<td align="center"><a href="../../../../../index.html">Home</a></td>
<td align="center"><a href="../../../../../libs/libraries.htm">Libraries</a></td>
<td align="center"><a href="http://www.boost.org/users/people.html">People</a></td>
<td align="center"><a href="http://www.boost.org/users/faq.html">FAQ</a></td>
<td align="center"><a href="../../../../../more/index.htm">More</a></td>
</tr></table>
<hr>
<div class="spirit-nav">
<a accesskey="p" href="differential_evolution.html"><img src="../../../../../doc/src/images/prev.png" alt="Prev"></a><a accesskey="u" href="../optimization.html"><img src="../../../../../doc/src/images/up.png" alt="Up"></a><a accesskey="h" href="../index.html"><img src="../../../../../doc/src/images/home.png" alt="Home"></a><a accesskey="n" href="random_search.html"><img src="../../../../../doc/src/images/next.png" alt="Next"></a>
</div>
<div class="section">
<div class="titlepage"><div><div><h2 class="title" style="clear: both">
<a name="math_toolkit.jso"></a><a class="link" href="jso.html" title="Algorithm jSO">Algorithm jSO</a>
</h2></div></div></div>
<h4>
<a name="math_toolkit.jso.h0"></a>
      <span class="phrase"><a name="math_toolkit.jso.synopsis"></a></span><a class="link" href="jso.html#math_toolkit.jso.synopsis">Synopsis</a>
    </h4>
<pre class="programlisting"><span class="preprocessor">#include</span> <span class="special">&lt;</span><span class="identifier">boost</span><span class="special">/</span><span class="identifier">math</span><span class="special">/</span><span class="identifier">optimization</span><span class="special">/</span><span class="identifier">jso</span><span class="special">.</span><span class="identifier">hpp</span><span class="special">&gt;</span>

<span class="keyword">namespace</span> <span class="identifier">boost</span><span class="special">::</span><span class="identifier">math</span><span class="special">::</span><span class="identifier">optimization</span> <span class="special">{</span>

<span class="keyword">template</span> <span class="special">&lt;</span><span class="keyword">typename</span> <span class="identifier">ArgumentContainer</span><span class="special">&gt;</span> <span class="keyword">struct</span> <span class="identifier">jso_parameters</span> <span class="special">{</span>
    <span class="keyword">using</span> <span class="identifier">Real</span> <span class="special">=</span> <span class="keyword">typename</span> <span class="identifier">ArgumentContainer</span><span class="special">::</span><span class="identifier">value_type</span><span class="special">;</span>
    <span class="identifier">ArgumentContainer</span> <span class="identifier">lower_bounds</span><span class="special">;</span>
    <span class="identifier">ArgumentContainer</span> <span class="identifier">upper_bounds</span><span class="special">;</span>
    <span class="identifier">size_t</span> <span class="identifier">initial_population_size</span> <span class="special">=</span> <span class="number">0</span><span class="special">;</span>
    <span class="identifier">size_t</span> <span class="identifier">max_function_evaluations</span> <span class="special">=</span> <span class="number">0</span><span class="special">;</span>
    <span class="identifier">ArgumentContainer</span> <span class="keyword">const</span> <span class="special">*</span> <span class="identifier">initial_guess</span> <span class="special">=</span> <span class="keyword">nullptr</span><span class="special">;</span>
<span class="special">};</span>

<span class="keyword">template</span> <span class="special">&lt;</span><span class="keyword">typename</span> <span class="identifier">ArgumentContainer</span><span class="special">,</span> <span class="keyword">class</span> <span class="identifier">Func</span><span class="special">,</span> <span class="keyword">class</span> <span class="identifier">URBG</span><span class="special">&gt;</span>
<span class="identifier">ArgumentContainer</span> <span class="identifier">jso</span><span class="special">(</span>
    <span class="keyword">const</span> <span class="identifier">Func</span> <span class="identifier">cost_function</span><span class="special">,</span> <span class="identifier">jso_parameters</span><span class="special">&lt;</span><span class="identifier">ArgumentContainer</span><span class="special">&gt;</span> <span class="keyword">const</span> <span class="special">&amp;</span><span class="identifier">jso_params</span><span class="special">,</span> <span class="identifier">URBG</span> <span class="special">&amp;</span><span class="identifier">gen</span><span class="special">,</span>
    <span class="identifier">std</span><span class="special">::</span><span class="identifier">invoke_result_t</span><span class="special">&lt;</span><span class="identifier">Func</span><span class="special">,</span> <span class="identifier">ArgumentContainer</span><span class="special">&gt;</span> <span class="identifier">target_value</span> <span class="special">=</span> <span class="identifier">std</span><span class="special">::</span><span class="identifier">numeric_limits</span><span class="special">&lt;</span><span class="identifier">std</span><span class="special">::</span><span class="identifier">invoke_result_t</span><span class="special">&lt;</span><span class="identifier">Func</span><span class="special">,</span> <span class="identifier">ArgumentContainer</span><span class="special">&gt;&gt;::</span><span class="identifier">quiet_NaN</span><span class="special">(),</span>
    <span class="identifier">std</span><span class="special">::</span><span class="identifier">atomic</span><span class="special">&lt;</span><span class="keyword">bool</span><span class="special">&gt;</span> <span class="special">*</span><span class="identifier">cancellation</span> <span class="special">=</span> <span class="keyword">nullptr</span><span class="special">,</span>
    <span class="identifier">std</span><span class="special">::</span><span class="identifier">atomic</span><span class="special">&lt;</span><span class="identifier">std</span><span class="special">::</span><span class="identifier">invoke_result_t</span><span class="special">&lt;</span><span class="identifier">Func</span><span class="special">,</span> <span class="identifier">ArgumentContainer</span><span class="special">&gt;&gt;</span> <span class="special">*</span><span class="identifier">current_minimum_cost</span> <span class="special">=</span> <span class="keyword">nullptr</span>
    <span class="identifier">std</span><span class="special">::</span><span class="identifier">vector</span><span class="special">&lt;</span><span class="identifier">std</span><span class="special">::</span><span class="identifier">pair</span><span class="special">&lt;</span><span class="identifier">ArgumentContainer</span><span class="special">,</span> <span class="identifier">std</span><span class="special">::</span><span class="identifier">invoke_result_t</span><span class="special">&lt;</span><span class="identifier">Func</span><span class="special">,</span> <span class="identifier">ArgumentContainer</span><span class="special">&gt;&gt;&gt;</span> <span class="special">*</span><span class="identifier">queries</span> <span class="special">=</span> <span class="keyword">nullptr</span><span class="special">);</span>

<span class="special">}</span> <span class="comment">// namespaces</span>
</pre>
<p>
      The <code class="computeroutput"><span class="identifier">jso</span></code> function provides a
      (hopefully) faithful implementation of Algorithm jSO, described in Brest et
      al 2017. This algorithm came in second place in the 2017 conference on evolutionary
      computing competition. It is an improvement on the classical differential evolution
      algorithm, which adapts the parameters in such as way that exploration is favored
      during early stages of the algorithm, and exploitation is favored during the
      later stages. In particular, it incorporates numerous ideas in the literature
      (in particular SHADE and L-SHADE) which aid in fast convergence. There are:
      Use of a historical archive of rejected vectors to provide information about
      convergence direction, adapting crossover and mutation parameters based on
      whether they were associated with successful updates, linear population size
      reduction, and use of "current-to-p-best" mutation.
    </p>
<p>
      Like our implementation of differential evolution, it minimizes a cost function
      defined on a continuous space represented by a set of bounds. Again this function
      has been designed more for progress observability, graceful cancellation, and
      post-hoc data analysis than for speed of convergence.
    </p>
<h4>
<a name="math_toolkit.jso.h1"></a>
      <span class="phrase"><a name="math_toolkit.jso.parameters"></a></span><a class="link" href="jso.html#math_toolkit.jso.parameters">Parameters</a>
    </h4>
<div class="itemizedlist"><ul class="itemizedlist" style="list-style-type: disc; ">
<li class="listitem">
          <code class="computeroutput"><span class="identifier">lower_bounds</span></code>: A container
          representing the lower bounds of the optimization space along each dimension.
          The <code class="computeroutput"><span class="special">.</span><span class="identifier">size</span><span class="special">()</span></code> of the bounds should return the dimension
          of the problem.
        </li>
<li class="listitem">
          <code class="computeroutput"><span class="identifier">upper_bounds</span></code>: A container
          representing the upper bounds of the optimization space along each dimension.
          It should have the same size of <code class="computeroutput"><span class="identifier">lower_bounds</span></code>,
          and each element should be &gt;= the corresponding element of <code class="computeroutput"><span class="identifier">lower_bounds</span></code>.
        </li>
<li class="listitem">
          <code class="computeroutput"><span class="identifier">initial_population_size</span></code>:
          How big the first generation should be. Defaults to <code class="computeroutput"><span class="identifier">ceil</span><span class="special">(</span><span class="number">25l</span><span class="identifier">og</span><span class="special">(</span><span class="identifier">D</span><span class="special">+</span><span class="number">1</span><span class="special">)</span><span class="identifier">sqrt</span><span class="special">(</span><span class="identifier">D</span><span class="special">))</span></code>
          where <code class="computeroutput"><span class="identifier">D</span></code> is the dimension
          of the problem.
        </li>
<li class="listitem">
          <code class="computeroutput"><span class="identifier">max_function_evaluations</span></code>:
          Defaults to 10000D, where <code class="computeroutput"><span class="identifier">D</span></code>
          is the dimension of the space.
        </li>
<li class="listitem">
          <code class="computeroutput"><span class="identifier">initial_guess</span></code>: An optional
          guess for where we should start looking for solutions.
        </li>
</ul></div>
<p>
      The defaults were chosen from a reading of Brest 2017.
    </p>
<h4>
<a name="math_toolkit.jso.h2"></a>
      <span class="phrase"><a name="math_toolkit.jso.the_function"></a></span><a class="link" href="jso.html#math_toolkit.jso.the_function">The
      function</a>
    </h4>
<pre class="programlisting"><span class="keyword">template</span> <span class="special">&lt;</span><span class="keyword">typename</span> <span class="identifier">ArgumentContainer</span><span class="special">,</span> <span class="keyword">class</span> <span class="identifier">Func</span><span class="special">,</span> <span class="keyword">class</span> <span class="identifier">URBG</span><span class="special">&gt;</span>
<span class="identifier">ArgumentContainer</span> <span class="identifier">jso</span><span class="special">(</span><span class="keyword">const</span> <span class="identifier">Func</span> <span class="identifier">cost_function</span><span class="special">,</span>
                      <span class="identifier">jso_parameters</span><span class="special">&lt;</span><span class="identifier">ArgumentContainer</span><span class="special">&gt;</span> <span class="keyword">const</span> <span class="special">&amp;</span><span class="identifier">jso_params</span><span class="special">,</span>
                      <span class="identifier">URBG</span> <span class="special">&amp;</span><span class="identifier">gen</span><span class="special">,</span>
                      <span class="identifier">std</span><span class="special">::</span><span class="identifier">invoke_result_t</span><span class="special">&lt;</span><span class="identifier">Func</span><span class="special">,</span> <span class="identifier">ArgumentContainer</span><span class="special">&gt;</span> <span class="identifier">value_to_reach</span>
                        <span class="special">=</span> <span class="identifier">std</span><span class="special">::</span><span class="identifier">numeric_limits</span><span class="special">&lt;</span><span class="identifier">std</span><span class="special">::</span><span class="identifier">invoke_result_t</span><span class="special">&lt;</span><span class="identifier">Func</span><span class="special">,</span> <span class="identifier">ArgumentContainer</span><span class="special">&gt;&gt;::</span><span class="identifier">quiet_NaN</span><span class="special">(),</span>
                      <span class="identifier">std</span><span class="special">::</span><span class="identifier">atomic</span><span class="special">&lt;</span><span class="keyword">bool</span><span class="special">&gt;</span> <span class="special">*</span><span class="identifier">cancellation</span> <span class="special">=</span> <span class="keyword">nullptr</span><span class="special">,</span>
                      <span class="identifier">std</span><span class="special">::</span><span class="identifier">atomic</span><span class="special">&lt;</span><span class="identifier">std</span><span class="special">::</span><span class="identifier">invoke_result_t</span><span class="special">&lt;</span><span class="identifier">Func</span><span class="special">,</span> <span class="identifier">ArgumentContainer</span><span class="special">&gt;&gt;</span> <span class="special">*</span><span class="identifier">current_minimum_cost</span> <span class="special">=</span> <span class="keyword">nullptr</span><span class="special">,</span>
                      <span class="identifier">std</span><span class="special">::</span><span class="identifier">vector</span><span class="special">&lt;</span><span class="identifier">std</span><span class="special">::</span><span class="identifier">pair</span><span class="special">&lt;</span><span class="identifier">ArgumentContainer</span><span class="special">,</span> <span class="identifier">std</span><span class="special">::</span><span class="identifier">invoke_result_t</span><span class="special">&lt;</span><span class="identifier">Func</span><span class="special">,</span> <span class="identifier">ArgumentContainer</span><span class="special">&gt;&gt;&gt;</span> <span class="special">*</span><span class="identifier">queries</span> <span class="special">=</span> <span class="keyword">nullptr</span><span class="special">)</span>
</pre>
<p>
      Parameters:
    </p>
<div class="itemizedlist"><ul class="itemizedlist" style="list-style-type: disc; ">
<li class="listitem">
          <code class="computeroutput"><span class="identifier">cost_function</span></code>: The cost
          function to be minimized.
        </li>
<li class="listitem">
          <code class="computeroutput"><span class="identifier">jso_params</span></code>: The parameters
          to the algorithm as described above.
        </li>
<li class="listitem">
          <code class="computeroutput"><span class="identifier">gen</span></code>: A uniform random bit
          generator, like <code class="computeroutput"><span class="identifier">std</span><span class="special">::</span><span class="identifier">mt19937_64</span></code>.
        </li>
<li class="listitem">
          <code class="computeroutput"><span class="identifier">value_to_reach</span></code>: An optional
          value that, if reached, stops the optimization. This is the most robust
          way to terminate the calculation, but in most cases the optimal value of
          the cost function is unknown. If it is, use it! Physical considerations
          can often be used to find optimal values for cost functions.
        </li>
<li class="listitem">
          <code class="computeroutput"><span class="identifier">cancellation</span></code>: An optional
          atomic boolean to allow the user to stop the computation and gracefully
          return the best result found up to that point. N.B.: Cancellation is not
          immediate; the in-progress generation finishes.
        </li>
<li class="listitem">
          <code class="computeroutput"><span class="identifier">current_minimum_cost</span></code>: An
          optional atomic variable to store the current minimum cost during optimization.
          This allows developers to (e.g.) plot the progress of the minimization
          over time and in conjunction with the <code class="computeroutput"><span class="identifier">cancellation</span></code>
          argument allow halting the computation when the progress stagnates.
        </li>
<li class="listitem">
          <code class="computeroutput"><span class="identifier">queries</span></code>: An optional vector
          to store intermediate results during optimization. This is useful for debugging
          and perhaps volume rendering of the objective function after the calculation
          is complete.
        </li>
</ul></div>
<p>
      Returns:
    </p>
<p>
      The argument vector corresponding to the minimum cost found by the optimization.
    </p>
<p>
      N.B.: The termination criteria is an "OR", not an "AND".
      So if the maximum generations is hit, the iteration stops, even if (say) a
      <code class="computeroutput"><span class="identifier">value_to_reach</span></code> has not been
      attained.
    </p>
<p>
      If you want more observability into what the optimization is doing, compile
      with <code class="computeroutput"><span class="special">-</span><span class="identifier">DBOOST_MATH_DEBUG_JSO</span><span class="special">=</span><span class="number">1</span></code>
    </p>
<h5>
<a name="math_toolkit.jso.h3"></a>
      <span class="phrase"><a name="math_toolkit.jso.examples"></a></span><a class="link" href="jso.html#math_toolkit.jso.examples">Examples</a>
    </h5>
<p>
      An example exhibiting graceful cancellation and progress observability can
      be studied in <a href="../../../example/jso_example.cpp" target="_top">jso_example.cpp</a>.
    </p>
<h5>
<a name="math_toolkit.jso.h4"></a>
      <span class="phrase"><a name="math_toolkit.jso.references"></a></span><a class="link" href="jso.html#math_toolkit.jso.references">References</a>
    </h5>
<div class="itemizedlist"><ul class="itemizedlist" style="list-style-type: disc; "><li class="listitem">
          Brest, Janez, Mirjam Sepesy Maučec, and Borko Bošković. <span class="emphasis"><em>Single
          objective real-parameter optimization: Algorithm jSO.</em></span> 2017 IEEE
          congress on evolutionary computation (CEC). IEEE, 2017.
        </li></ul></div>
</div>
<div class="copyright-footer">Copyright © 2006-2021 Nikhar Agrawal, Anton Bikineev, Matthew Borland,
      Paul A. Bristow, Marco Guazzone, Christopher Kormanyos, Hubert Holin, Bruno
      Lalande, John Maddock, Evan Miller, Jeremy Murphy, Matthew Pulver, Johan Råde,
      Gautam Sewani, Benjamin Sobotta, Nicholas Thompson, Thijs van den Berg, Daryle
      Walker and Xiaogang Zhang<p>
        Distributed under the Boost Software License, Version 1.0. (See accompanying
        file LICENSE_1_0.txt or copy at <a href="http://www.boost.org/LICENSE_1_0.txt" target="_top">http://www.boost.org/LICENSE_1_0.txt</a>)
      </p>
</div>
<hr>
<div class="spirit-nav">
<a accesskey="p" href="differential_evolution.html"><img src="../../../../../doc/src/images/prev.png" alt="Prev"></a><a accesskey="u" href="../optimization.html"><img src="../../../../../doc/src/images/up.png" alt="Up"></a><a accesskey="h" href="../index.html"><img src="../../../../../doc/src/images/home.png" alt="Home"></a><a accesskey="n" href="random_search.html"><img src="../../../../../doc/src/images/next.png" alt="Next"></a>
</div>
</body>
</html>
